<template>
  <div style="width:98%;height:100%;margin:0 auto;margin-top:10px">
    <el-card class="box-card">
      <div class="btn" shadow="always">
        <!-- <el-button type="primary" size="small" @click="protocol">新建配置</el-button> -->
      </div>
      <!-- 表格展示 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="agreementTitle" label="协议标题" align="center"></el-table-column>
        <el-table-column
          prop="agreementContent"
          label="协议内容"
          align="center"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column prop="agreementType" label="协议类型" align="center">
          <template slot-scope="scope">
            <span>{{agreementTypeStatus(scope.row.agreementType)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="primary" size="small">查看/编辑</el-button>
            <!-- <el-button @click="delethandleClick(scope.row)" type="danger" size="small">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <!-- <el-pagination
        background
        layout="total,  prev, pager, next, jumper"
        :total="total"
        :current-page="current"
        style="margin-top:24px"
        @current-change="currentpange"
      ></el-pagination>-->
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      current: 1,
      total: 0
    };
  },
  mounted() {
    this.getTableDataList();
  },
  methods: {
    getTableDataList() {
      var param = {
        size: 10,
        current: this.current
      };
      this.$http.article.getUserdeploy(param).then(res => {
        this.tableData = res.result.records;
        this.total = res.result.total;
        //显示每页展示的数量
        res.result.records.forEach((item, index) => {
          //res.data.data.list 表格数据     forEach为每一项添加数据
          item.index = index + 1 + (this.current - 1) * 10;
          // this.currentPage当前页  this.pageParams.size 每页显示多少    :page-sizes="[10,20,30,50]" 分页大小

          return item;
        });
        console.log("获取用户协议列表", res);
      });
    },
    // 判断协议状态
    agreementTypeStatus(val) {
      if (val == 1) return "关于我们";
      if (val == 2) return "用户协议";
      if (val == 3) return "隐私协议";
      if (val == 4) return "游戏协议";
      console.log("获取协议状态", val);
    },
    // 新建协议
    // protocol() {
    //   console.log("新建协议");
    //   this.$router.push("/home/addprotocol");
    //   //   this.$router.push("/home/newadmin");
    // },
    // 查看用户协议信息
    handleClick(val) {
      console.log("查看用户协议", val);
      this.$router.push({
        path: "/home/addprotocol",
        query: { agreementId: val.agreementId }
      });
    }
    //分页数据
    // currentpange(val) {
    //   this.current = val;
    //   this.getTableDataList();
    // },
    // 删除用户协议数据
    // delethandleClick(val) {
    //   this.$confirm("是否确认删除？", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning"
    //   })
    //     .then(() => {
    //       this.$http.article
    //         .deletUserdeploy({ yj_agreementId: val.agreementId })
    //         .then(res => {
    //           if (res.code == 200) {
    //             /*--------删除成功之后获取上一页的数据,避免是否为空--------*/

    //             //此时已经实现删除操作，所以total的值需要减size，Math.ceil是向上取整，保证始终大于等于0
    //             const totalPage = Math.ceil((this.total - 1) / 10);

    //             console.log("totalPage", totalPage);

    //             //将当前页码与删除数据之后的总页数进行比较，避免当前页码不存在
    //             const pagenum =
    //               this.current > totalPage ? totalPage : this.current;

    //             console.log("获取总条数", pagenum);

    //             //避免pagenum变为0
    //             this.current = pagenum < 1 ? 1 : pagenum;
    //             // 提示弹窗
    //             this.$message.success("删除成功!");
    //             this.getTableDataList();
    //           }
    //         });
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "已取消删除"
    //       });
    //     });
    // }
  }
};
</script>
<style lang="css">
.el-tooltip__popper {
  /* display: none; */
  cursor: pointer;
  font-size: 14px;
  max-width: 70%;
  padding-bottom: 5px!important;
  border: 1px solid #ccc;
  background: #ffffff !important; 
  /* opacity: 0.5 !important; */
  color: #000 !important; 
}
</style>
<style lang="scss" scoped>
.btn {
  display: flex;
  justify-content: flex-end;
}
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}
</style>